﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Torch_Services
{
    public class MeetingResultBll : IMeetingResultBll
    {
        private IMeetingResultDal _meet;
        private IMapper _mapper;
        public MeetingResultBll(IMeetingResultDal meet, IMapper mapper)
        {
            _meet = meet;
            _mapper = mapper;
        }

        public async Task<int> AddMeetingResultAsync(int meetingRecord, string meetingInfo, string meetingPerson, DateTime EndTime)
        {
            return await _meet.AddAsync(new Meetingresult 
            {
                MeetingRecord = meetingRecord,
                MeetingInfo = meetingInfo,
                MeetingPerson = meetingPerson,
                EndTime = EndTime
            });
        }

        public async Task<int> DeleteMeetingResultAsync(int id)
        {
            var data = await _meet.QueryAsync(id);
            return data == null ? -1 : await _meet.DeleteAsync(data);
        }

        public async Task<int> EditMeetingResultAsync(int id, int meetingRecord, string meetingInfo, string meetingPerson, DateTime EndTime)
        {
            var data = await _meet.QueryAsync(id);
            if (data == null)
                return -1;
            data.MeetingRecord = meetingRecord;
            data.MeetingInfo = meetingInfo;
            data.MeetingPerson = meetingPerson;
            data.EndTime = EndTime;
            return await _meet.EditAsync(data);
        }

        public async Task<List<MeetingResultDto>> GetMeetingResultAllAsync()
        {
            var data = await _meet.QueryAsync();
            return _mapper.Map<List<Meetingresult>,List<MeetingResultDto>>(data);
        }

        public async Task<MeetingResultDto> QueryMeetingResultByIdAsync(int id)
        {
            var data = await _meet.QueryAsync(id);
            return _mapper.Map<Meetingresult, MeetingResultDto>(data);
        }
    }
}
